//
//  BrowserWebView.h
//  CLBrowser
//
//  Created by 梁慧聪 on 2016/10/4.
//  Copyright © 2021年 梁慧聪. All rights reserved.
//

#import <UIKit/UIKit.h>
#import <WebKit/WebKit.h>
#import "CLWebViewBridge.h"
#import "CLNovelView.h"
@class CLWebView, CLWebModel, CLWebViewBackForwardList, CLHomePageView;

typedef void (^CLWebCompletionBlock)(NSString *, NSError *);
typedef void(^CLBackForwardListCompletion)(CLWebViewBackForwardList *);

@protocol WebViewDelegate <NSObject>

@optional

#pragma mark - UIWebViewDelegate

- (BOOL)webView:(CLWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType;

- (BOOL)webView:(CLWebView *)webView decidePolicyForNavigationAction:(WKNavigationAction *)navigationAction decisionHandler:(void (^)(WKNavigationActionPolicy))decisionHandler;

- (void)webViewDidStartLoad:(CLWebView *)webView;
- (void)webViewDidFinishLoad:(CLWebView *)webView;
- (void)webView:(CLWebView *)webView didFailLoadWithError:(NSError *)error;
- (void)webView:(CLWebView *)webView hiddenTopBar:(BOOL)isHiddenTopBar;
- (void)webView:(CLWebView *)webView hiddenBottomBar:(BOOL)isHiddenBottomBar;

@end
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
@interface CLWebView : WKWebView<WKNavigationDelegate,WKUIDelegate>
#pragma clang diagnostic pop

@property (nonatomic, assign) CLWebModel *webModel;
@property (nonatomic, assign, readonly) BOOL isMainFrameLoaded;
@property (nonatomic, strong, readonly) UIActivityIndicatorView *indicatorView;
@property (nonatomic, strong, readonly) UILongPressGestureRecognizer *longPressGestureRecognizer;
@property (nonatomic, strong) NSURLRequest *request;
@property (nonatomic, copy) NSString *HTMLSource;
@property (nonatomic, strong) CLWebViewBridge *bridge;
@property (nonatomic, strong) CLHomePageView *homePage;
@property (nonatomic, assign) BOOL isMain;

- (NSString *)mainFURL;
- (NSString *)mainFTitle;
- (void)webViewBackForwardListWithCompletion:(CLBackForwardListCompletion)completion;
- (void)startWithUrl:(NSString *)url;

//得到title回调
- (void)clWebView:(id)sender didReceiveTitle:(id)title forFrame:(id)frame;
- (void)clWebView:(id)webView resource:(id)resource didReceiveAuthenticationChallenge:(id)challenge fromDataSource:(id)source;
//new window 回调，现在很多网站已经做移动版适配，很少会使用新窗口打开了
- (void)clWebView:(id)webView decidePolicyForNewWindowAction:(id)actionInformation request:(id)request newFrameName:(id)frameName decisionListener:(id)listener;
//navigation 回调,如果想实现点击url新窗口打开可以判断intNaviType是否为WebNavigationTypeLinkClicked
- (void)clWebView:(id)webView decidePolicyForNavigationAction:(id)actionInformation request:(id)request frame:(id)frame decisionListener:(id)listener;
- (void)clWebViewDidUpdateUI;
@end
